package com.base.config;

import org.springframework.cache.interceptor.KeyGenerator;

import java.lang.reflect.Method;
import java.util.Arrays;

public class MyKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object o, Method method, Object... params) {
        if (params.length == 0) {
            return method.getName() + "[Empty]";
        } else if (params.length == 1) {
            Object param = params[0];
            if (param != null && !param.getClass().isArray()) {
                return method.getName() + "[" + param + "]";
            }
        }
        return method.getName() + "[" + Arrays.toString(params) + "]";

    }
}
